package com.itqianfeng.dao.utils;

import java.sql.*;

public interface DbHelper {

    String url = "jdbc:mysql://localhost:3306/sql_store";
    String user = "root";
    String password = "da1234";


    default Connection getConnection(){
         Connection connection = null;
         try {
              connection = DriverManager.getConnection(url, user, password);
         } catch (SQLException e) {
              e.printStackTrace();
         }
         return connection;
    }

    default void  close(Connection con , PreparedStatement ps , ResultSet rs){
         try {
              if (rs != null && !rs.isClosed()) {
                   rs.close();
              }
         } catch (SQLException e) {
              e.printStackTrace();
         } finally {
              try {
                   if (ps != null && !ps.isClosed()) ps.close();
              } catch (SQLException e) {
                   e.printStackTrace();
              } finally {
                   try {
                        if (con != null  && !con.isClosed()) con.close();
                   } catch (SQLException e) {
                        e.printStackTrace();
                   }

              }
         }
    }

}
